#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
typedef struct {
    int* arr;
    int head;
    int tail;
    int size;
    int k;
} MyCircularQueue;

bool myCircularQueueIsFull(MyCircularQueue* obj);
bool myCircularQueueIsEmpty(MyCircularQueue* obj);
MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* pst = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    pst->arr = (int*)malloc((k + 1) * sizeof(int));
    pst->head = 0;
    pst->tail = 0;
    pst->size = 0;
    pst->k = k;
    return pst;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;
    else
    {
        if (obj->tail == obj->k)
        {
            obj->arr[obj->tail] = value;
            obj->tail = 0;
            obj->size++;
        }
        else
        {
            obj->arr[obj->tail] = value;
            obj->tail++;
            obj->size++;
        }
        return true;
    }
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;
    if (obj->head == obj->k)
    {
        obj->head = 0;
        obj->size--;

        return true;
    }
    else
    {
        obj->head++;
        obj->size--;
        return true;

    }
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;
    else
        return obj->arr[obj->head];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;
    else
    {
        if (obj->tail == 0)
        {
            return obj->arr[obj->k];
        }
        else
        {
            return obj->arr[obj->tail - 1];
        }
    }
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->head == obj->tail;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    if (obj->size == obj->k)
        return true;
    else
        return false;
}

void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->arr);
    free(obj);
}

int main()
{
    MyCircularQueue* obj = myCircularQueueCreate(2);
    myCircularQueueEnQueue(obj, 1);
    myCircularQueueEnQueue(obj, 2);
    myCircularQueueDeQueue(obj);
    myCircularQueueEnQueue(obj, 3);
    myCircularQueueDeQueue(obj);
    myCircularQueueEnQueue(obj, 3);
    myCircularQueueDeQueue(obj);
    myCircularQueueEnQueue(obj, 3);
    myCircularQueueDeQueue(obj);
    int i = myCircularQueueFront(obj);
    printf("%d ", i);

    return 0;
}